class PromptConfig:
    _instance = None
    max_history = 0
    save_conversation_history = ""
    load_conversation_history = ""
    modelname = ""
    class_of_prompt = 0

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super().__new__(cls)
            # 初始化默认配置
            cls._instance.update_config_based_on_class()
        return cls._instance

    def update_config_based_on_class(self):
        """根据class_of_prompt更新配置"""
        if self.class_of_prompt == 0:
            self.max_history = 50
            self.save_conversation_history = r"C:\Users\Lenovo\Desktop\challenge_cup\Chain_of_model\model_chain\chat_history\history.json"
            self.load_conversation_history = self.save_conversation_history
            self.modelname = "qwen2.5-coder:14b"
        elif self.class_of_prompt == -1:
            self.max_history = 0
            self.save_conversation_history = ""
            self.load_conversation_history = ""
            self.modelname = ""

    @classmethod
    def set_max_history(cls, max_history):
        cls._instance.max_history = max_history

    @classmethod
    def set_conversation_history(cls, save_path):
        cls._instance.save_conversation_history = save_path
        cls._instance.load_conversation_history = save_path

    @classmethod
    def set_modelname(cls, modelname):
        cls._instance.modelname = modelname

    @classmethod
    def set_class_of_prompt(cls, class_of_prompt):
        # 修改实例的属性而非类属性
        cls._instance.class_of_prompt = class_of_prompt
        # 根据新的类型更新配置
        cls._instance.update_config_based_on_class()

if __name__ == '__main__':
    # 无论创建多少个实例，都是同一个对象
    config1 = PromptConfig()
    config2 = PromptConfig()

    print("初始配置:")
    print(f"max_history: {config1.max_history}")
    print(f"modelname: {config1.modelname}")
    print(f"class_of_prompt: {config1.class_of_prompt}")
    print(f"save_conversation_history: {config1.save_conversation_history}")

    # 通过第一个实例修改配置
    config1.set_class_of_prompt(-1)
    config1.set_modelname("new-model:7b")

    print("\n修改后通过第二个实例查看:")
    print(f"max_history: {config2.max_history}")
    print(f"modelname: {config2.modelname}")
    print(f"class_of_prompt: {config2.class_of_prompt}")
    print(f"save_conversation_history: {config2.save_conversation_history}")
    print(f"save_conversation_history: {config1.save_conversation_history}")
    # 验证是否为同一个实例
    print(f"\n是否为同一个实例: {config1 is config2}")

    config = PromptConfig()
    print("\n第三个实例查看:")
    print(f"max_history: {config2.max_history}")
    print(f"modelname: {config2.modelname}")
    print(f"class_of_prompt: {config2.class_of_prompt}")
